import logging

import config


class RegisterLoginAPI:

    # 1、 获取图片验证码接口
    @classmethod
    def get_image_code(cls,session,r):
        url = config.Host + f"/common/public/verifycode1/{r}"
        logging.info(f"获取图片验证码接口的URL={url}")
        resp = session.get(url)
        return resp

    # 2、 获取短信验证码接口
    @classmethod
    def get_phone_code(cls,session,phone,imgVerifyCode):
        url = config.Host + "/member/public/sendSms"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"phone":phone,"imgVerifyCode":imgVerifyCode,"type":"reg"}
        logging.info(f"获取短信验证码接口的URL={url}")
        logging.info(f"获取短信验证码接口的请求体body={body}")
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 3、 注册接口
    @classmethod
    def regist(cls,session,phone,password,verifycode,phone_code):
        url = config.Host + "/member/public/reg"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"phone":phone,"password":password,"verifycode":verifycode,"phone_code":phone_code,
                "dy_server":"on","invite_phone":""}
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 4、 登录接口
    @classmethod
    def login(cls,session,keywords,password):
        url = config.Host + "/member/public/login"
        header = {"Content-Type":"application/x-www-form-urlencoded"}
        body = {"keywords":keywords,"password":password}
        resp = session.post(url=url,headers=header,data=body)
        return resp

    # 5、 查询登录状态接口
    @classmethod
    def select_login_status(cls,session):
        url = config.Host + "/member/public/islogin"
        resp = session.post(url=url)
        return resp

